#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<sys/select.h>
#include<mysql.h>
#include<string.h>

struct password
{
	char id[20];
	char passwd[20];
	int flag;
};

void online_member(int connectfd,struct password pw)
{
    	MYSQL mysql;
    	MYSQL_RES *res = NULL;
    	char mysql_insert[100];
	char buf[20];
    	int fields;
    	MYSQL_ROW row;
    	int rows,rc,i=0;
    	if(NULL == mysql_init(&mysql)) 
	{  
	        printf("mysql_init(): %s\n", mysql_error(&mysql));  
        	return -1;  
    	}  
    	if (NULL == mysql_real_connect(&mysql,  
			"localhost",  
                	"root",  
                	"root",  
                	"lts",  
                	 0,  
                	NULL,  
                	0)) 
	{  
        	printf("mysql_real_connect(): %s\n", mysql_error(&mysql));  
        	return -1;  
    	}  
    	strcpy(mysql_insert,"select * from user");
	rc = mysql_query(&mysql,mysql_insert);
	if(rc!=0)
	{
		printf("mysql_query(): %s\n", mysql_error(&mysql)); 
	}
    	res = mysql_store_result(&mysql);
    	if (NULL == res) 
	{
         	printf("mysql_store_result(): %s\n", mysql_error(&mysql));
         	return 0;
    	}
    	fields = mysql_num_fields(res);
   	while ((row = mysql_fetch_row(res))) 
	{
		memset(buf,'\0',sizeof(buf));
		if(strcmp(row[2],"0")==0)    
		{
			continue;
		}
		else
		{       
			
			strcpy(buf,row[0]);
			send(connectfd,buf,sizeof(buf),0);
			
		}
    	}		
	send(connectfd,"end",sizeof(buf),0);
	mysql_close(&mysql); 
}
